Imports capaLogica

Public Class VentanaModificarEliminarCurso
    Dim estaCargado As Boolean
    Dim indexFilaModificada As Integer
    'Dim ultimoSeleccionado As Boolean = False
    'Dim acabaDeBorrar As Boolean = False
    Dim id As String

    Public Sub New()

        ' This call is required by the Windows Form Designer.

        InitializeComponent()
        estaCargado = False
        ' Add any initialization after the InitializeComponent() call.


    End Sub
    
    Private Sub VentanaModificarEliminarCurso_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.LlenarCursos()
    End Sub
    Private Sub LlenarCursos()

        Try
            'TODO correcion de arquitectura
            Me.DataGridViewCursos.DataSource = MultiGrupo.LevantarCursos

            With Me.DataGridViewCursos.Columns.Item("esGrupal")
                .Visible = False
                .SortMode = DataGridViewColumnSortMode.NotSortable
            End With
            With Me.DataGridViewCursos.Columns.Item("nombreCurso")
                .HeaderText = "Nombre"
                .SortMode = DataGridViewColumnSortMode.NotSortable
            End With
            With Me.DataGridViewCursos.Columns.Item("idCurso")
                .HeaderText = "Codigo"
                .SortMode = DataGridViewColumnSortMode.NotSortable
            End With


        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

        estaCargado = True
    End Sub

    Private Sub DataGridViewCursos_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewCursos.CellEndEdit
        If estaCargado Then
            Dim codigo, nombre As String
            If Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(0).Value IsNot System.DBNull.Value Then
                codigo = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(0).Value
            Else
                codigo = ""
            End If
            If Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(1).Value IsNot System.DBNull.Value Then
                nombre = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(1).Value
            Else
                nombre = ""
            End If

            Dim gestor As GestorRegistrarGrupo = New GestorRegistrarGrupo()
            gestor.ModificarCurso(codigo, nombre, id)
        End If
    End Sub

    Private Sub DataGridViewCursos_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewCursos.CellEnter
        If estaCargado Then
            indexFilaModificada = Me.DataGridViewCursos.CurrentRow.Index
            If Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(0).Value IsNot System.DBNull.Value Then

                id = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(0).Value
            End If

        End If
    End Sub



    Private Sub DataGridViewCursos_RowsRemoved(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles DataGridViewCursos.RowsRemoved
        Dim gestor As GestorRegistrarGrupo = New GestorRegistrarGrupo()

        If estaCargado Then
            gestor.EliminarCurso(id)
            Me.DataGridViewCursos.Rows(0).Selected() = True
        End If
    End Sub
    'Private Sub DataGridViewCursos_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewCursos.CellLeave
    '    If estaCargado Then
    '        Dim codigo, nombre As String
    '        Dim id As Integer

    '        codigo = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(0).Value
    '        nombre = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(1).Value
    '        id = Me.DataGridViewCursos.Rows(indexFilaModificada).Cells(3).Value

    '        Dim gestor As GestorRegistrarGrupo = New GestorRegistrarGrupo()
    '        gestor.ModificarCurso(codigo, nombre, id)
    '    End If
    'End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class